package com.lamatek.tags.google;

import java.io.Serializable;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import com.lamatek.tags.google.beans.EscapeChars;

/**
 * GoogleMapInfoWindowTag
 * 
 * This class represents a &lt;googlemaps:infowindow> tag. Developers should not override this
 * class.
 * 
 * @author Tom Cole
 * @version 0.40
 */
public class GoogleMapInfoWindowTag extends BodyTagSupport implements Serializable, InfoWindow {
    
    boolean display = false;
    String content;
    boolean html = true;
    String style = null;
    String css_class = null;
    /**
     * Denotes that this tag is not tabbed.
     * 
     * @return false
     */
    public boolean isTabbed() {
        return false;
    }
    /**
     * Overrides doStartTag from BodyTagSupport.
     */
    public int doStartTag() {
        return EVAL_BODY_BUFFERED;
    }
    /**
     * Overrides doEndTag from BodyTagSupport. Developers should not override this method.
     */
    public int doEndTag() {
        if (content == null) {
            content = getBodyContent().getString().trim();
            if (html)
                content = EscapeChars.escape(content);
        }
        Tag tag = this;
        while (tag.getParent() != null) {
            if (tag.getParent() instanceof GoogleMapMarkerTag) {
                ((GoogleMapMarkerTag) tag.getParent()).setInfoWindow(this);
                return EVAL_PAGE;
            }
            tag = tag.getParent();
        }
        return EVAL_PAGE;
    }
    /**
     * Sets whether or not this info window should be initially displayed. If set to
     * true then the info window will be displayed. If set to false, the info window will
     * only display after the user has clicked on the parent marker.
     * 
     * @param display True to display, false to require a click to display.
     */
    public void setDisplay(boolean display) {
        this.display = display;
    }
    /**
     * Returns the body content of this info window. If html is set to true, this will return
     * an escaped version. 
     * 
     * @return The body contents of the window as a String.
     */
    public String getContent() {
        return content;
    }
    /**
     * Sets the body content of this info window. If html is set to true, this content will
     * be escaped. If this content contains html, you should call setHtml(true) <em>before</em>
     * calling this method. If this is set,
     * the content between the starting tag and ending tag will be ignored.
     * 
     * @param content The displayed contents for this window. 
     */
    public void setContent(String content) {
        if (html)
            this.content = EscapeChars.escape(content.trim());
        else
            this.content = content.trim();
    }
    /**
     * Returns true if this window is set to initially display. Returns false otherwise.
     * 
     * @return true or false.
     */
    public boolean isDisplay() {
        return display;
    }
    /**
     * Denotes whether or not the contents of this tag are html and therefore
     * need to be escaped.
     * 
     * @return True or false.
     */
    public boolean isHtml() {
        return html;
    }
    /**
     * Sets whether or not the contents of this tag are html and therefore need
     * to be escaped.
     * 
     * @param html True if content needs to be escaped, false if not.
     */
    public void setHtml(boolean html) {
        this.html = html;
    }
    /**
     * Gets the css style attribute for this window's content.
     * 
     * @return The CSS style attribute(s)
     */
    public String getStyle() {
        return style;
    }
    /**
     * Sets the css style attribute for this window's content.
     * 
     * @param style CSS style attribute(s)
     */
    public void setStyle(String style) {
        this.style = style;
    }
    /**
     * Gets the css class attribute for this window's content.
     * 
     * @return The CSS class attribute(s)
     */
    public String getCss_class() {
        return css_class;
    }
    /**
     * Sets the css style attribute for this window's content.
     * 
     * @param style CSS style attribute(s)
     */
    public void setCss_class(String css_class) {
        this.css_class = css_class;
    }
}
